package com.truyen.service.impl;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import com.truyen.service.MailService;
import com.truyen.utils.MailMail;
import com.truyen.utils.PropertyResolver;


@Service
public class MailServiceImpl implements MailService {
	
	@Autowired
	private MailMail mailMail;
	
	@Autowired
	private PropertyResolver propertyResolver;

	@Async
	@Override
	public void sendNotify(String subject, String content, String toEmail) {
		mailMail.setFromAddress("pepon8x@gmail.com");
		mailMail.setToAddress(toEmail);
		mailMail.setAttach(false);// khong co dinh kem file
		mailMail.sendMail(content, subject);
	}

	@Async
	@Override
	public void sendNotify(String subject, String content, String toEmail,
			String fromEmail) {
		mailMail.setFromAddress(fromEmail);
		mailMail.setToAddress(toEmail);
		mailMail.setAttach(false);// khong co dinh kem file
		mailMail.sendMail(content, subject);
//		String url = propertyResolver.getValue("app.sendMailPath")+"?api_user="+propertyResolver.getValue("app.sendMailUser")+"&api_key="+propertyResolver.getValue("app.sendMailPass")+"&to="+toEmail+"&toname="+toEmail+"&subject="+subject+"&html="+content+"&from="+fromEmail;
//		String responseSend = restTemplate.getForObject(url, String.class);
//		logger.debug("=====================================> Send "+toEmail+": "+responseSend);
	}
}
